package com.yao.spider.core.util;


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Properties;

/**
 * Created by 单耀 on 2017/12/24.
 */
public class SimpLogger extends Logger {
    protected SimpLogger(String name) {
        super(name);
    }

    private static Properties setLogProperty() {
        Properties p = new Properties();
        String ip = null;
        try {
            p.load(SimpLogger.class.getResourceAsStream("/log4j.properties"));
            InetAddress addr = InetAddress.getLocalHost();
            ip = addr.getHostAddress().toString();//获取本机ip
        } catch (IOException e) {
            e.printStackTrace();
        }

        return p;
    }

    public static Logger getSimpleLogger(Class<?> c) {
        Logger logger = Logger.getLogger(c);
        PropertyConfigurator.configure(setLogProperty());
        return logger;
    }
}
